package com.summer.back.user;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.NoHandlerFoundException;

import com.summer.common.Const;
import com.summer.common.ServerResponse;
import com.summer.user.pojo.User;
import com.summer.user.pojo.UserLogin;
import com.summer.user.service.IUserService;

/** 
 * @描述：后台管理页面-管理员操作接口
 * @作者：yang 
 * @时间：2017年6月20日 下午9:54:10 
 * @版本：1.0
 */
@RestController
@RequestMapping("/manage/user/")
public class UserManageController {

	@Resource
	private IUserService iUserService;
	
	@PostMapping("login")
	public ServerResponse<UserLogin> login(String username, String password, HttpSession session) {
		ServerResponse<UserLogin> response = iUserService.login(username, password);
		if(response.isSuccess()) {
			UserLogin user = response.getData();
			if(user.getRole() == Const.Role.ROLE_ADMIN) {
				session.setAttribute(Const.CURRENT_USER, user);
				return response;
			} else {
				return ServerResponse.createByErrorMessage("不是管理员，无法登录！");
			}
		}
		return response;
	}
	
	@GetMapping(value = "test")
	public Object test() {
		System.out.println("Hello 也是ffff");
		return new HttpMediaTypeNotSupportedException("我还能说什么呢");
	}
}
